<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数据代理</title>
  </head>
  <body>
    <!-- <div id="root">
        <h1>hello.{{name}}{{Date.now()}}</h1>
    </div> -->
    <script type="text/javascript">
      var data = {
        name: "马冬梅",
        age: 28,
      };

      var vm = {};
      vm._data = data = new Observer(data);

      function Observer(obj) {
        const keys = Object.keys(obj);
        keys.forEach((k) => {
          Object.defineProperty(this, k, {
            get() {
              return obj[k];
            },
            set(val) {
              obj[k] = val;
            },
          });
        });
      }
    </script>
  </body>
</html>
